import com.sfx.User;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2022-11-06
 * Time: 19:57
 */
public class APP1 {

    public static void main(String[] args) {
        //1.获取到Spring上下文对象 , 因为我们是从XML文件进行获取Bean的. 要指定从哪个XML获取bean
        BeanFactory context = new XmlBeanFactory(new ClassPathResource("spring-config.xml"));
        //2.获取到bean对象
        //以前获取对象的方式  User user = new User();//在spring中就不要出现了,耦合度高

        //2.3通过 bean的 id 和 类型 来获取到bean对象  最稳妥的做法
        User user = context.getBean("user",User.class);
        user.sayHello();

    }
}
